﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace SimpoBudgetDataModel
{
    public class Account
    {

        private int id;
        private string name;
        private decimal balance;
        private string url;

        public Account()
        { }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string Url
        {
            get { return url; }
            set { url = value; }
        }

        public decimal Balance
        {
            get { return balance; }
            set { balance = value; }
        }
               
        public void LoadAccountByName(string AccountName)
        {
            string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=SimpoBudget;Integrated Security=True;MultipleActiveResultSets=True";
            SqlDataReader accountSqlDataReader;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {

                connection.Open();
                // Do work here.

                SqlCommand sqlSelect = new SqlCommand("EXEC sp_GetAccountByName " + AccountName, connection);
                accountSqlDataReader = sqlSelect.ExecuteReader();
                accountSqlDataReader.Read();

                id = accountSqlDataReader.GetFieldValue<int>(0);
                name = accountSqlDataReader.GetFieldValue<string>(1);
                //url = accountSqlDataReader.GetFieldType(2).ToString();
                balance = accountSqlDataReader.GetFieldValue<decimal>(2);
                url = accountSqlDataReader.GetFieldValue<string>(3);
               
            }

        }

    }
}
